home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / editor / auror300.zip / COUNTCHR.AML < prev    next >
Text File  |  1996-07-17  |  3KB  |  101 lines

  1. //--------------------------------------------------------------------
  2. // COUNTCHR.AML
  3. // Count Characters, (C) 1993-1996 by nuText Systems
  4. //
  5. // This macro counts the number of characters in the current file and
  6. // displays the result. The count is limited to a marked block if it
  7. // exists.
  8. //
  9. // The total number of characters reported is the number of bytes that
  10. // the file or marked block would occupy on disk if it were saved,
  11. // including line delimiter characters.
  12. //
  13. // Usage:
  14. //
  15. // Select this macro from the Macro List (on the Macro menu), or run it
  16. // from the macro picklist <shift f12>.
  17. //--------------------------------------------------------------------
  18.  
  19. include bootpath "define.aml"
  20.  
  21. variable total_char
  22.  
  23. // edit windows only
  24. if not wintype? "edit" then
  25.   msgbox "Edit windows only!"
  26.   return
  27. end
  28.  
  29. // if nothing is marked, then temporarily mark the whole file
  30. if mark? then
  31.   if getcurrbuf <> getmarkbuf then
  32.     msgbox "Mark must be in current window"
  33.     return
  34.   end
  35. else
  36.   tempmark = TRUE             // flag indicating temporary mark
  37.   markline 1 (getlines)       // mark entire file
  38. end
  39.  
  40. marktype = getmarktype        // get the mark type
  41. firstline = getmarktop        // get the top line of the mark
  42. lastline = getmarkbot         // get the bottom line of the mark
  43. currbuf (getmarkbuf)          // make marked buffer the current buffer
  44. pushcursor                    // save cursor position
  45. row (getmarktop)              // goto the top of the marked block
  46.  
  47. // do for all lines in the mark
  48. repeat
  49.  
  50.   total_char = total_char +   // add size to total
  51.  
  52.     case marktype
  53.  
  54.       // line marks
  55.       when 'l'
  56.         getlinelen
  57.  
  58.       // column marks
  59.       when 'k'
  60.         length (gettext (getmarkleft) (getmarkcols))
  61.  
  62.       // character/stream marks
  63.       otherwise
  64.         if getrow == firstline then
  65.           length (gettext (getmarkleft)
  66.                         (if firstline == lastline then
  67.                            getmarkcols
  68.                          end))
  69.         elseif getrow == lastline then
  70.           length (gettext 1 (getmarkright))
  71.         else
  72.           getlinelen
  73.         end
  74.     end
  75.  
  76. until not down or getrow > lastline
  77. breakoff
  78.  
  79. // restore cursor position
  80. popcursor
  81.  
  82. // compute the space that would be occupied by delimiter
  83. // characters if the marked block was saved (zero for binary files)
  84. if not getbinarylen then
  85.   delimitspace = getmarkrows * length (hex2bin _LineDlm)
  86. end
  87.  
  88. // destroy mark if temporary
  89. if tempmark then
  90.   destroymark
  91. end
  92.  
  93. display
  94.  
  95. // display the totals
  96. shortbox (if? tempmark "Entire file: " "Marked Block: ") +
  97.          (thousands total_char + delimitspace) + " chars (" +
  98.          (thousands total_char) + " text + " +
  99.          (thousands delimitspace) + " delimiter)"
  100.        "Character Count"
  101.